#include "ContainsExitForm.h"
#include <QPainter>
#include <QMouseEvent>

ContainsExitForm::ContainsExitForm(ElementForm* parent)
	:ElementForm(parent),_isPressed(false),_startPos(0,0)
	,_endPos(0,0),_exitRect(67,54,72,72)
{
}
void ContainsExitForm::paintEvent(QPaintEvent* event)
{
	QPainter painter(this);
	painter.setRenderHints(QPainter::Antialiasing, true);
	CommonFunc::drawExitBtn(&painter, _exitRect);
	ElementForm::paintEvent(event);
}

void ContainsExitForm::mousePressEvent(QMouseEvent* event)
{
	_startPos = event->pos();
	_isPressed = true;
	QWidget::mousePressEvent(event);
}

void ContainsExitForm::mouseReleaseEvent(QMouseEvent* event)
{
	if (_isPressed) {
		if (_exitRect.contains(event->pos())&&_exitRect.contains(_startPos)){
			longPress();
		}
	}

	_startPos = QPoint(0, 0);
	_endPos = QPoint(0, 0);
	_isPressed = false;
	QWidget::mouseReleaseEvent(event);
}
